package com.example.beatbox;

import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.example.beatbox.databinding.ListItemSoundBinding;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

public class SoundAdapter extends RecyclerView.Adapter<SoundHolder> {

    private List<Sound> mSounds;
    private BeatBox mBeatBox;

    public SoundAdapter(List<Sound> sounds, BeatBox beatBox) {
        mSounds = sounds;
        mBeatBox = beatBox;
    }

    @NonNull
    @Override
    public SoundHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        ListItemSoundBinding binding = DataBindingUtil.inflate(inflater,
                R.layout.list_item_sound, parent, false);
        return new SoundHolder(binding,mBeatBox);
    }

    @Override
    public void onBindViewHolder(@NonNull SoundHolder holder, int position) {
        Sound sound=mSounds.get(position);
        holder.bind(sound);
    }

    @Override
    public int getItemCount() {
        return mSounds.size();
    }
}
